/**
 * Created by Administrator on 2017/3/2 0002.
 */
var Game={
    create:function () {
        var game={};
        game.ui=new PIXI.DisplayObjectContainer();
        var arr_page=[];
        var page0 = Page0.create();
        var page1 = Page1.create();
        var page2 = Page2.create();
        var page3 = Page3.create();
        arr_page.push(page1,page2,page3);

        var con=new PIXI.DisplayObjectContainer();
        for(var i=0;i<arr_page.length;i++)
        {
            con.addChild(arr_page[i].ui);
            arr_page[i].ui.y=1136*i;
        }
        Scroller.create(con,pixiStageW,pixiStageH,'ver',arr_page.length-1);

        game.ui.addChild(page0.ui);
        page0.In();

        // game.ui=con;
        document.addEventListener('Game_ScrollComplete',scrollCompleteHander);
        document.addEventListener('Game_ScrollStart',scrollStartHander);
        document.addEventListener('Game_ScrollIn',scrollInHandler);
        document.addEventListener('Game_Page0Out',page0OutHandler);

        function scrollInHandler(e) {
            TweenMax.to(pd.emitterContainer,0,{alpha:0});
            pd.emitter.emit = false;
            con.interactive=false;
            game.ui.addChildAt(con,0);
            setTimeout(function () {
                con.interactive=true;
                arr_page[0].In();
            },2000)
        }
        function page0OutHandler(e) {
            game.ui.removeChild(page0.ui);
        }
        function scrollStartHander(e) {
            console.log('out',e.detail);

            arr_page[e.detail].Out();
        }
        function scrollCompleteHander(e) {
            arr_page[e.detail].In();
        }

        var pageSub0=PageSub0.create();
        var pageSub1=PageSub1.create();
        var pageSub2=PageSub2.create();
        var pageSub3=PageSub3.create();
        document.addEventListener('Game_SubPageIn',subInHander);
        function subInHander(e) {
            if(e.detail=='i0')
            {
                stage.addChild(pageSub3.ui);
                pageSub3.In();
            }
            else if(e.detail=='i1')
            {
                stage.addChild(pageSub2.ui);
                pageSub2.In();
            }
            else if(e.detail=='i3')
            {
                stage.addChild(pageSub1.ui);
                pageSub1.In();
            }
            else if(e.detail=='i2')
            {
                stage.addChild(pageSub0.ui);
                pageSub0.In();
            }
        }
        
        
        return game;
    }

}